package gridModel;

import java.io.Serializable;

public class GridSize implements Comparable<GridSize>, Serializable {
	
	// ATTRIBUTS
	
	private static final long serialVersionUID = 1L;
	
	public static final int MIN_WIDTH = 5;
	public static final int MAX_WIDTH = 40;
	public static final int MIN_HEIGHT = 5;
	public static final int MAX_HEIGHT = 40;
	
	private int width;
	private int height;
	
	// CONSTRUCTEUR
	
	public GridSize(int x, int y) {
		if (x < MIN_WIDTH || y < MIN_HEIGHT || x > MAX_WIDTH || y > MAX_HEIGHT) {
			throw new IllegalArgumentException();
		}
		width = x;
		height = y;
	}
	
	// REQUETES
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}
	
	public int compareTo(GridSize g) {
		double w0 = getWidth(),
			w1 = g.getWidth(),
			h0 = getHeight(),
			h1 = g.getHeight();
		if (w0 < w1 || w0 == w1 && h0 < h1) {
			return -1;
		}
		if (w0 == w1 && h0 == h1) {
			return 0;
		}
		return 1;
	}
	
	public boolean equals(Object o) {
		return o != null && ((GridSize) o).getWidth() == width && ((GridSize) o).getHeight() == height;
	}
	
	public String toString() {
		return getWidth() + "x" + getHeight();
	}
	
}